﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 工厂模式
{
    class Program
    {
        static void Main(string[] args)
        {
            Driver d = new BenzDriver();
            Car c = d.SelectCar();
            c.Run();
        }
    }

    /// <summary>
    /// 抽象的产品
    /// </summary>
    interface Car
    {
        void Run();
    }
    /// <summary>
    /// 具体的产品
    /// </summary>
    class Benz:Car
    {
        public void Run()
        {
            Console.WriteLine("奔驰跑");
        }
    }
    /// <summary>
    /// 具体的产品
    /// </summary>
    class BMW : Car
    {
        public void Run()
        {
            Console.WriteLine("宝马跑");
        }
    }

    /// <summary>
    /// 抽象的工厂
    /// 司机会选择车
    /// </summary>
    abstract class Driver
    {
        public abstract Car SelectCar();
    }
    /// <summary>
    /// 开奔驰的司机只能选择奔驰车开
    /// 具体的工厂
    /// </summary>
    class BenzDriver:Driver
    {
        public override Car SelectCar()
        {
            return new Benz();
        }
    }
    /// <summary>
    /// 开宝马的司机只能选择宝马车
    /// 具体的工厂
    /// </summary>
    class BMWDriver : Driver
    {
        public override Car SelectCar()
        {
            return new BMW();
        }
    }
}
